#include <stdafx.h>
#include "RdcTransport.h"
#include "ClientChannelBuilder.h"
#include "ClientWriteStrategy.h"
#include "ClientReadStrategy.h"
#include "ServerChannelBuilder.h"
#include "ServerReadStrategy.h"
#include "ServerWriteStrategy.h"

std::auto_ptr<rdc_transport::IVirtChannel> rdc_transport::CreateClientChannel(
    __in const char* szChannelName,
    __in PCHANNEL_ENTRY_POINTS pEntryPoints,
    __in IClientVirtChannelCallback* pCallback,
    __in IReadHandler* pReadHandler,
    __in bool bShowProtocol /*= false*/)
{
    if(bShowProtocol)
    {
        Client::ChannelBuilder<WriteWithProtocol, ReadStrategy> builder(CHANNEL_OPTION_SHOW_PROTOCOL);
        return builder.GetResult(szChannelName, pEntryPoints, pCallback, pReadHandler);
    }
    else
    {
        Client::ChannelBuilder<WriteNoProtocol, ReadStrategy> builder(0);
        return builder.GetResult(szChannelName, pEntryPoints, pCallback, pReadHandler);
    }
}

std::auto_ptr<rdc_transport::IVirtChannel> rdc_transport::CreateServerChannel(
    __in const char* szChannelName,
    __in LPTSTR szAddinRGSName,
    __in IServerVirtChannelCallback* pCallback,
    __in IReadHandler* pReadHandler,
    __in bool bShowProtocol /*= false*/)
{
    if (bShowProtocol)
    {
        Server::ChannelBuilder<ServerWriteStrategy, ServerReadStrategy<ServerReadWithProtocol>> builder;
        return builder.GetResult(szChannelName, szAddinRGSName, pCallback, pReadHandler);
    }
    else
    {
        Server::ChannelBuilder<ServerWriteStrategy, ServerReadStrategy<ServerReadNoProtocol>> builder;
        return builder.GetResult(szChannelName, szAddinRGSName, pCallback, pReadHandler);
    }
}